#include<fstream>
#include<iostream>
#include<string>
#include<sstream>
#include<map>
#include<set>
#include<vector>
using std::endl;
using std::cout;
using std::ifstream;
using std::string;
using std::map;
using std::istringstream;
using std::vector;
using std::set;



void worldNum(string &line);
int main(void){
    map<string,int> worldNums;
    //map<string,int> worldNum;
    map<string,int> _dic;
    string Line;
    int id = 0;
    ifstream ifs("china_daily.txt");
    if(!ifs.good()){
        cout<<"ifs open file fail!"<<endl;
        return -1;
    }
    while(std::getline(ifs,Line)){
        if(Line.empty()){
            continue;
        }
        //需要空行
        id++;
        //cout<<Line<<endl;
        //cout<<"id:"<<id<<" "<< Line.size()<<" "<<Line <<endl;
        _dic.insert({Line,id});
        //统计单词
        worldNum(Line);
    }

    for(auto &ele : worldNums){
        cout<<ele.first<<"     "<<ele.second<<endl;
    }
    cout<<endl;
    return 0;
}
#if 0
void worldNum(string &line,map<string,int>&worldNums){
    string world;
    istringstream iss(line);
    while(iss>>world){
        if(ispunct(world.back())){
            //移除尾部标点符号
                world.erase(world.find(world.back()));
            }
        if(ispunct(world.front())){
            //移除头部标点符号
            world.erase(world.find(world.front()));
        }
        //大小写转换
        if(isupper(world[0])){
            world[0] = tolower(world[0]);
        }
        //如过该单词出现过，就不统计
        bool isExit = false;
        //该行出现过哈 一会儿要改
        for(auto &ele : worldNums){
            if(world == ele.first){
                //出现过
                isExit = true;
                ++ele.second;
                break;
            }
        }
        if(isExit!=true){
            worldNums.insert({world,1});
        }
    }
}
#endif